"""
    测试用例
"""
import unittest
import requests

from apiunittest import keyword
from apiunittest.lib.loadIni import LoadIni
from apiunittest.keyword.keyword import Keyword
from apiunittest.lib.excel import Excel
from apiunittest.lib.log import logger
from apiunittest.lib.excelrequest import ExcelRequest
from ddt import ddt, file_data, data
# Excel数据
excelData = Excel('../data/demo.xlsx').readExcel('Sheet1')


@ddt
class ApiTest(unittest.TestCase):

    @classmethod
    def setUpClass(cls) -> None:
        cls.keyword = Keyword()
        cls.cookie = None
        cls.confData = LoadIni('config.ini')
        logger.info('----------用例开始执行----------')

    # 登录
    # @file_data('../data/data.yaml')
    # def test_1_login(self, username, password):
    #     s = requests.Session()
    #     loginUrl = self.confData.getConfig('urlConfig', 'login')
    #
    #     data = {
    #         'uname': username,
    #         'upass': password,
    #         'encode': 1
    #     }
    #     res = s.post(url=loginUrl, data=data)
    #     logger.info(res.text)
    #     cookie = dict(res.cookies)
    #     sess = jsonpath.jsonpath(cookie, '$..{0}'.format('PHPSESSION'))
    #     phpSession = 'PHP_SESSION=' + sess[0]
    #     ApiTest.cookie = phpSession
    #     logger.info('用例执行成功')

    @data(*excelData)
    def test_2_excel(self, excel):
        rowNum = int(excel['ID'])
        res = ExcelRequest.requests(requests, excel)
        if self.keyword.getText(res, 'code') != excel['code']:
            resStatus = "FAIL"
        else:
            resStatus = "PASS"

        Excel('../data/demo.xlsx').writeExcel(rowNum + 1, resStatus)


if __name__ == '__main__':
    unittest.main()